// ============================================================================
//  gDestroyerFireAlt.uc ::
// ============================================================================
class gDestroyerFireAlt extends gNoFire;

var int currentammo;


simulated function bool AllowFire()
{
    return (Weapon.AmmoAmount(ThisModeNum) > 0);
}

function DoFireEffect()
{
    GotoState('');
    if( Weapon.AmmoAmount(ThisModeNum) <= 0 )
        Weapon.OutOfAmmo();
}

event ModeHoldFire()
{
    if( Weapon.AmmoAmount(ThisModeNum) > 0 )
    {
        super.ModeHoldFire();
        GotoState('Hold');
    }
}

simulated function PlayFiring()
{
    Super.PlayFiring();
    Weapon.OutOfAmmo();
}

simulated function GetFireCoords( out vector AimLoc, out rotator AimRot )
{
    local vector X,Y,Z;

    Weapon.GetViewAxes(X, Y, Z);
    AimLoc = GetFireStart(X, Y, Z);
    AimRot = AdjustAim(AimLoc, AimError);
}

state Hold
{
    simulated event BeginState()
    {

        // don't even spawn on server
        if( Level.NetMode != NM_DedicatedServer && xPlayer(Instigator.Controller) != None )
        {
            if(FlashEffectClass != None )
            {
                FlashEffect = Spawn(FlashEffectClass);
                if( FlashEffect != None && FlashBone != '' )
                {
                    Weapon.AttachToBone(FlashEffect, FlashBone);
                    if( FlashBoneRotator != rot(0,0,0) )
                        Weapon.SetBoneRotation( FlashBone, FlashBoneRotator, 0, 1 );
                }
            }
        }

        gDestroyer(Weapon).BeamBegin();
        Weapon.PlayAnim(PreFireAnim);
        SetTimer(FireRate, True);
        Timer();
    }

    simulated event Timer()
    {
        if( Weapon.AmmoAmount(ThisModeNum) == 0 )
        {
            SetTimer(0.0, False);
        }
        else
        {
            Weapon.ConsumeAmmo(ThisModeNum, 1);
            currentammo = Weapon.AmmoAmount(ThisModeNum);
            //Hack to fix destroyer ammo bug
            if(currentammo == 7)
                Weapon.ConsumeAmmo(ThisModeNum, 7);

            if( Weapon.AmmoAmount(ThisModeNum) <= 0 )
            {
                GotoState('');
                Weapon.OutOfAmmo();
            }
        }
    }

    simulated event EndState()
    {
        gDestroyer(Weapon).BeamEnd();
        if( FlashEffect != None )
        {
            FlashEffect.Kill();
            FlashEffect = None;
        }
    }

    function StopFiring()
    {
        Super.StopFiring();
        GotoState('');
    }
}

simulated function InitEffects()
{
}


// ============================================================================
// DefaultProperties
// ============================================================================

defaultproperties
{
     FlashBoneRotator=(Yaw=16384,Roll=16384)
     FlashBone="Muzzle"
     StartOffset=(Z=-16.000000)
     PreFireSound=Sound'TFMedia.Destroyer.de_altfire_begin'
     FireLoopSound=Sound'TFMedia.Destroyer.de_altfire_loop'
     FireEndSound=Sound'TFMedia.Destroyer.de_altfire_end'
     bFireOnRelease=True
     bWaitForRelease=True
     PreFireAnim="alt_begin"
     FireLoopAnim="alt_loop"
     FireEndAnim="alt_end"
     FireRate=0.060000
     AmmoClass=Class'Taskforces.gDestroyerAmmo'
}
